<template>
  <div class="container-content">
    <el-form
      ref="formRef"
      :model="kingAssembleEntity"
      label-width="90px"
      label-position="left"
    >
      <el-card shadow="never" class="mt20">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="单据编号">
              <el-input
                v-model="kingAssembleEntity.kingAssembleEntity.docNo"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="单据类型">
              <el-select
                v-model="kingAssembleEntity.kingAssembleEntity.docTypeCode"
                placeholder=""
                style="width: 100%"
              >
                <el-option label="标准组装拆卸" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="事务类型">
              <el-select
                v-model="kingAssembleEntity.kingAssembleEntity.transactionType"
                placeholder=""
                style="width: 100%"
              >
                <el-option label="组装" value="Assembly"></el-option>
                <el-option label="拆卸" value="Dassembly"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="日期">
              <el-date-picker
                v-model="kingAssembleEntity.kingAssembleEntity.bizTime"
                type="date"
                placeholder="选择日期"
                style="width: 100%"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="部门">
              <el-input
                v-model="kingAssembleEntity.kingAssembleEntity.bizDeptName"
                suffix-icon="el-icon-search"
                @focus="openList('部门')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="仓管员">
              <el-input
                v-model="kingAssembleEntity.kingAssembleEntity.keeperUserName"
                suffix-icon="el-icon-search"
                @focus="openList('仓管员')"
              >
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="成品货主类型">
              <el-select
                v-model="
                  kingAssembleEntity.kingAssembleEntity.productShipperType
                "
                placeholder=""
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option label="业务组织" value="BD_OwnerOrg"></el-option>
                <el-option label="供应商" value="BD_Supplier"></el-option>
                <el-option label="客户" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成品货主">
              <el-input
                v-model="
                  kingAssembleEntity.kingAssembleEntity.productShipperName
                "
                suffix-icon="el-icon-search"
                @focus="openList('成品货主')"
              >
              </el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="库存组">
              <el-input
                v-model="
                  kingAssembleEntity.kingAssembleEntity.inventoryDeptCode
                "
                suffix-icon="el-icon-search"
                @focus="openList('库存组')"
              >
              </el-input>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-row :gutter="20">
          <!-- <el-col :span="12">
            <el-form-item label="成品货主类型">
              <el-select
                v-model="
                  kingAssembleEntity.kingAssembleEntity.productShipperType
                "
                placeholder=""
                style="width: 100%"
                @change="selectshipper"
              >
                <el-option label="业务组织" value="BD_OwnerOrg"></el-option>
                <el-option label="供应商" value="BD_Supplier"></el-option>
                <el-option label="客户" value="BD_Customer"></el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :span="24">
            <el-form-item label="描述">
              <el-input
                v-model="kingAssembleEntity.kingAssembleEntity.remarks"
                type="textarea"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-card>
      <div class="desc-title">
        成品列表
        <el-button type="text" class="openBOM" @click="openBOM"
          >展开BOM</el-button
        >
      </div>

      <el-table
        :data="kingAssembleEntity.kingAssembleDetailEntities"
        style="width: 100%"
        highlight-current-row
        border
      >
        <template #empty
          ><el-button plain type="primary" round @click="addNewRow"
            >添加新行</el-button
          ></template
        >
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              plain
              icon="el-icon-plus"
              size="small"
              @click="handleDataAdd(scope.$index, scope.row)"
            ></el-button>
            <el-button
              plain
              icon="el-icon-minus"
              size="small"
              @click="handleDataDelete(scope.$index, scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column type="index" width="50"> </el-table-column>
        <el-table-column label="物料编码">
          <template slot-scope="scope">
            <el-form-item label-width="0px" style="margin: 0">
              <el-input v-model="scope.row.materialCode">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('物料编码', scope.$index)"
                ></i>
              </el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.materialName"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.model"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="单位">
          <template slot-scope="scope">
            <el-input clearable v-model="scope.row.materialUnit">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('单位', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.num"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓库">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehouseCode">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('仓库', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehousePosition"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="库存状态">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryStateCode"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="批号">
          <template slot-scope="scope">
            <el-input v-model="scope.row.batchNo" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="费用">
          <template slot-scope="scope">
            <el-input v-model="scope.row.fee"></el-input>
          </template>
        </el-table-column>
        <!-- <el-table-column label="参照BOM版本">
          <template slot-scope="scope">
            <el-input v-model="scope.row.bomVersion">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('参照bom版本', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column> -->
        <el-table-column label="备注">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remarks"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <div class="desc-title">子项列表</div>
      <el-table
        :data="kingAssembleDetailEntitiesChid"
        style="width: 100%"
        highlight-current-row
        border
      >
        <template #empty
          ><el-button plain type="primary" round @click="addNewRowChid"
            >添加新行</el-button
          ></template
        >
        <el-table-column label="操作" width="120px">
          <template slot-scope="scope">
            <el-button
              plain
              icon="el-icon-plus"
              size="small"
              @click="handleDataAddChid(scope.$index, scope.row)"
            ></el-button>
            <el-button
              plain
              icon="el-icon-minus"
              size="small"
              @click="handleDataDeleteChid(scope.$index, scope.row)"
            ></el-button>
          </template>
        </el-table-column>
        <el-table-column type="index" width="50"> </el-table-column>

        <el-table-column label="物料编码">
          <template slot-scope="scope">
            <el-form-item label-width="0px" style="margin: 0">
              <el-input v-model="scope.row.materialCode">
                <i
                  slot="suffix"
                  class="el-icon-search"
                  @click="openList('子项物料编码', scope.$index)"
                ></i>
              </el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column label="物料名称">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.materialName"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="规格型号">
          <template slot-scope="scope">
            <el-input disabled v-model="scope.row.model"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="单位">
          <template slot-scope="scope">
            <el-input clearable v-model="scope.row.materialUnit">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('子项单位', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="数量">
          <template slot-scope="scope">
            <el-input v-model="scope.row.num"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓库">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehouseCode">
              <i
                slot="suffix"
                class="el-icon-search"
                @click="openList('子项仓库', scope.$index)"
              ></i>
            </el-input>
          </template>
        </el-table-column>
        <el-table-column label="仓位">
          <template slot-scope="scope">
            <el-input v-model="scope.row.warehousePosition"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="库存状态">
          <template slot-scope="scope">
            <el-input v-model="scope.row.inventoryStateCode"></el-input>
          </template>
        </el-table-column>
        <el-table-column label="批号">
          <template slot-scope="scope">
            <el-input v-model="scope.row.batchNo" disabled></el-input>
          </template>
        </el-table-column>
        <el-table-column label="备注">
          <template slot-scope="scope">
            <el-input v-model="scope.row.remarks"></el-input>
          </template>
        </el-table-column>
      </el-table>
      <el-dialog
        width="60%"
        :title="title"
        :visible.sync="dialogTableVisible"
        :append-to-body="flag"
      >
        <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '部门'">
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column
            property="deptCode"
            label="编码"
            width="150"
          ></el-table-column>
          <el-table-column
            property="deptId"
            label="助记码"
            width="200"
          ></el-table-column>
          <el-table-column property="deptName" label="名称"></el-table-column>
          <el-table-column
            property="parentName"
            label="上级部门"
          ></el-table-column>
          <el-table-column
            property=""
            label="HR部门"
            width="200"
          ></el-table-column>
          <el-table-column property="" label="来源于s-HR"></el-table-column>
          <el-table-column property="status" label="数据状态"></el-table-column>
          <el-table-column property="" label="禁用状态"></el-table-column>
          <el-table-column
            property="deptName"
            label="部门全称"
          ></el-table-column>
        </el-table>
        <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '仓管员'">
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column property="nickName" label="名称"></el-table-column>
          <el-table-column
            property="userCode"
            label="职员编码"
          ></el-table-column>
          <el-table-column property="deptName" label="部门"></el-table-column>
          <el-table-column property="isUsed" label="禁用状态"></el-table-column>
        </el-table>
        <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '库存组'">
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column
            property="shipperCode"
            label="业务组编码"
          ></el-table-column>
          <el-table-column
            property="address"
            label="业务组名称"
          ></el-table-column>
          <el-table-column
            property="address"
            label="业务组类型"
          ></el-table-column>
          <el-table-column property="address" label="启用"></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="shipper == 'BD_OwnerOrg' && title == '成品货主'"
        >
          <el-table-column
            property="businessCode"
            label="编码"
            width="150"
          ></el-table-column>
          <el-table-column
            property="businessName"
            label="名称"
            width="200"
          ></el-table-column>
          <el-table-column property="address" label="形态"></el-table-column>
          <el-table-column
            property="address"
            label="核算组织"
          ></el-table-column>
          <el-table-column
            property="address"
            label="核算组织类型"
            width="200"
          ></el-table-column>
          <el-table-column
            property="businessDept"
            label="业务组织"
          ></el-table-column>
          <el-table-column
            property="address"
            label="组织职能"
          ></el-table-column>
          <el-table-column
            property="isEnabled"
            label="数据状态"
          ></el-table-column>
          <el-table-column
            property="describeInfo"
            label="描述"
          ></el-table-column>
          <el-table-column property="address" label="联系人"></el-table-column>
          <el-table-column
            property="address"
            label="联系电话"
          ></el-table-column>
          <el-table-column property="address" label="地址"></el-table-column>
          <el-table-column property="address" label="创建人"></el-table-column>
          <el-table-column
            property="address"
            label="创建日期"
          ></el-table-column>
          <el-table-column property="address" label="修改人"></el-table-column>
          <el-table-column
            property="address"
            label="修改日期"
          ></el-table-column>
          <el-table-column
            property="address"
            label="禁用状态"
          ></el-table-column>
          <el-table-column property="address" label="禁用人"></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="shipper == 'BD_Supplier' && title == '成品货主'"
        >
          <el-table-column
            property="supplierCode"
            label="编码"
            width="150"
          ></el-table-column>
          <el-table-column
            property="supplierName"
            label="名称"
            width="200"
          ></el-table-column>
          <el-table-column property="forShort" label="简称"></el-table-column>
          <el-table-column
            property="supplierGroup"
            label="供应商分组"
          ></el-table-column>
          <el-table-column
            property="examineId"
            label="审核人"
            width="200"
          ></el-table-column>
          <el-table-column
            property="examineTime"
            label="审核日期"
          ></el-table-column>
          <el-table-column
            property="dataState"
            label="数据状态"
          ></el-table-column>
          <el-table-column
            property="disabledState"
            label="禁用状态"
          ></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="shipper == 'BD_Customer' && title == '成品货主'"
        >
          <el-table-column
            property="customerCode"
            label="客户编码"
            width="150"
          ></el-table-column>
          <el-table-column
            property="customerName"
            label="客户名称"
            width="200"
          ></el-table-column>
          <el-table-column
            property="abbreviation"
            label="简称"
          ></el-table-column>
          <el-table-column
            property="supplierGroup"
            label="单据状态"
          ></el-table-column>
          <el-table-column
            property="isUsed"
            label="禁用状态"
            width="200"
          ></el-table-column>
          <el-table-column
            property="examineTime"
            label="审核人"
          ></el-table-column>
          <el-table-column
            property="dataState"
            label="审核日期"
          ></el-table-column>
          <el-table-column
            property="customerGroup"
            label="客户分组"
          ></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="title == '物料编码'"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column
            property="materialCode"
            label="编码"
          ></el-table-column>
          <el-table-column
            property="materialName"
            label="名称"
          ></el-table-column>
          <el-table-column property="model" label="规格型号"></el-table-column>
          <!-- <el-table-column
            property="isChange"
            label="数据状态"
          ></el-table-column>
          <el-table-column property="isUsed" label="禁用状态"></el-table-column> -->
          <el-table-column
            property="typeName"
            label="物料属性"
          ></el-table-column>
          <el-table-column property="unit" label="基本单位"></el-table-column>
          <!-- <el-table-column property="isUsed" label="已使用"></el-table-column> -->
        </el-table>
        <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '单位'">
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column
            property="meteringUnitCode"
            label="编码"
          ></el-table-column>
          <el-table-column
            property="meteringUnitName"
            label="名称"
          ></el-table-column>
          <el-table-column
            property="isBase"
            label="基准计量单位"
          ></el-table-column>
          <el-table-column property="isUsed" label="数据状态"></el-table-column>
        </el-table>
        <el-table :data="gridData"  @row-dblclick="getRow" v-if="title == '仓库'">
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column
            property="shipperCode"
            label="编码"
          ></el-table-column>
          <el-table-column property="address" label="名称"></el-table-column>
          <el-table-column
            property="address"
            label="仓库地址"
          ></el-table-column>
          <el-table-column
            property="address"
            label="仓库负责人"
          ></el-table-column>
          <el-table-column
            property="address"
            label="仓库属性"
          ></el-table-column>
          <el-table-column
            property="address"
            label="第三方仓储类型"
          ></el-table-column>
          <el-table-column
            property="address"
            label="数据状态"
          ></el-table-column>
          <el-table-column
            property="address"
            label="允许即时库负库存"
          ></el-table-column>
          <el-table-column
            property="address"
            label="启用仓位管理"
          ></el-table-column>
          <el-table-column
            property="address"
            label="不参与可发量统计"
          ></el-table-column>
          <el-table-column
            property="address"
            label="参与预警"
          ></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="title == '参照bom版本'"
        >
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column
            property="bomVersion"
            label="BOM版本"
          ></el-table-column>
          <el-table-column property="bomAs" label="BOM简称"></el-table-column>
          <el-table-column
            property="bomClassify"
            label="BOM分类"
          ></el-table-column>
          <el-table-column
            property="parentMaterialCode"
            label="父项物料编码"
          ></el-table-column>
          <el-table-column
            property="parMaterialName"
            label="物料名称"
          ></el-table-column>
          <el-table-column property="model" label="规格型号"></el-table-column>
          <el-table-column
            property="isChange"
            label="数据状态"
          ></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="title == '子项物料编码'"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55"> </el-table-column>
          <el-table-column
            property="materialCode"
            label="编码"
          ></el-table-column>
          <el-table-column
            property="materialName"
            label="名称"
          ></el-table-column>
          <el-table-column property="model" label="规格型号"></el-table-column>
          <!-- <el-table-column
            property="isChange"
            label="数据状态"
          ></el-table-column>
          <el-table-column property="isUsed" label="禁用状态"></el-table-column> -->
          <el-table-column
            property="typeName"
            label="物料属性"
          ></el-table-column>
          <el-table-column property="unit" label="基本单位"></el-table-column>
          <!-- <el-table-column property="isUsed" label="已使用"></el-table-column> -->
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="title == '子项单位'"
        >
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column
            property="meteringUnitCode"
            label="编码"
          ></el-table-column>
          <el-table-column
            property="meteringUnitName"
            label="名称"
          ></el-table-column>
          <el-table-column
            property="isBase"
            label="基准计量单位"
          ></el-table-column>
          <el-table-column property="isUsed" label="数据状态"></el-table-column>
        </el-table>
        <el-table
          :data="gridData"
           @row-dblclick="getRow"
          v-if="title == '子项仓库'"
        >
          <!-- <el-table-column type="selection" width="55"> </el-table-column> -->
          <el-table-column
            property="shipperCode"
            label="编码"
          ></el-table-column>
          <el-table-column property="address" label="名称"></el-table-column>
          <el-table-column
            property="address"
            label="仓库地址"
          ></el-table-column>
          <el-table-column
            property="address"
            label="仓库负责人"
          ></el-table-column>
          <el-table-column
            property="address"
            label="仓库属性"
          ></el-table-column>
          <el-table-column
            property="address"
            label="第三方仓储类型"
          ></el-table-column>
          <el-table-column
            property="address"
            label="数据状态"
          ></el-table-column>
          <el-table-column
            property="address"
            label="允许即时库负库存"
          ></el-table-column>
          <el-table-column
            property="address"
            label="启用仓位管理"
          ></el-table-column>
          <el-table-column
            property="address"
            label="不参与可发量统计"
          ></el-table-column>
          <el-table-column
            property="address"
            label="参与预警"
          ></el-table-column>
        </el-table>

        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogTableVisible = false">取 消</el-button>
          <el-button type="primary" @click="dialogTableVisible = false"
            >确 定</el-button
          >
        </span>
      </el-dialog>
    </el-form>
  </div>
</template>
<script>
import {
  editKingAssembleList,
  getMaterial,
  getKingDocTypeList,
  getMaterialList,
  getKingBaseBusinessGroupList,
  getKinguserList,
  getdeptList,
  getKingBaseMeteringUnitList,
  getWarehouseList,
  getCustomerList,
  getSupplierList,
  getList,
  getKingBomList,
  updataKingAssembleList,
} from "@/api/bim/bim";
export default {
  props: ["listid"],
  data() {
    return {
      shipper: "",
      flag: true,
      dialogTableVisible: false,
      title: "",
      kingAssembleEntity: {
        kingAssembleDetailEntities: [],
        kingAssembleEntity: {},
      },
      kingAssembleDetailEntitiesChid: [],
      dataList: [],
      gridData: [],
      count: 0,
      ids: [],
    };
  },
  methods: {
    //
    // 展开BOM
    openBOM() {
      for (
        let i = 0;
        i < this.kingAssembleEntity.kingAssembleDetailEntities.length;
        i++
      ) {
        this.ids.push(this.kingAssembleEntity.kingAssembleDetailEntities[i].id);
      }
      console.log(this.ids);
      getKingBomList({
        ids: this.ids,
      }).then((res) => {
        if (res.code == 200) {
          console.log(res);
        }
      });
    },
    selectshipper(val) {
      this.shipper = val;
    },
    // 获取选中列表 val 为数组
    handleSelectionChange(val) {
      this.kingAssembleEntity.kingAssembleDetailEntities = val;
      this.handleDataAdd();
    },
    // 获取每次点击的内容进行区分，并在此方法内进行打开弹窗及数据的请求
    openList(item, i) {
      this.dialogTableVisible = true;
      this.title = item;
      this.count = i;
      if (this.title == "部门") {
        getdeptList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.data;
          }
        });
      } else if (this.title == "仓管员") {
        getKinguserList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "成品货主") {
        // 业务组织类型
        if (this.shipper == "BD_OwnerOrg") {
          getKingBaseBusinessGroupList().then((res) => {
            if (res.code == 200) {
              this.gridData = res.rows;
            }
          });
          // 供应商组织
        } else if (this.shipper == "BD_Supplier") {
          getSupplierList().then((res) => {
            if (res.code == 200) {
              this.gridData = res.rows;
            }
          });
          // 客户组织
        } else if (this.shipper == "BD_Customer") {
          getCustomerList().then((res) => {
            if (res.code == 200) {
              this.gridData = res.rows;
            }
          });
        }
      } else if (this.title == "库存组") {
        this.gridData = [];
      } else if (this.title == "物料编码" || this.title == "子项物料编码") {
        getMaterialList().then((res) => {
          if (res.code == 200) {
            console.log(res);
            this.gridData = res.data.records;
          }
        });
      } else if (this.title == "单位" || this.title == "子项单位") {
        getKingBaseMeteringUnitList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "仓库" || this.title == "子项仓库") {
        getWarehouseList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      } else if (this.title == "参照bom版本") {
        getWarehouseList().then((res) => {
          if (res.code == 200) {
            this.gridData = res.rows;
          }
        });
      }
    },
    // 获取点击的表格内容并且关闭弹窗且进行内容的回显
    getRow(row) {
      this.dialogTableVisible = false;
      if (this.title == "部门") {
        // deptName
        this.kingAssembleEntity.kingAssembleEntity.bizDeptCode = row.deptId;
        this.kingAssembleEntity.kingAssembleEntity.bizDeptName = row.deptName;
      } else if (this.title == "仓管员") {
        this.kingAssembleEntity.kingAssembleEntity.keeperUserCode = row.deptId;
        this.kingAssembleEntity.kingAssembleEntity.keeperUserName =
          row.nickName;
      } else if (this.title == "成品货主") {
        //  kingAssembleEntity.kingAssembleEntity.productShipperCode
        if (this.shipper == "BD_OwnerOrg") {
          this.kingAssembleEntity.kingAssembleEntity.productShipperCode =
            row.businessCode;
          this.kingAssembleEntity.kingAssembleEntity.productShipperName =
            row.businessName;
          // 供应商组织
        } else if (this.shipper == "BD_Supplier") {
          this.kingAssembleEntity.kingAssembleEntity.productShipperCode =
            row.supplierCode;
          this.kingAssembleEntity.kingAssembleEntity.productShipperName =
            row.supplierName;
          // 客户组织
        } else if (this.shipper == "BD_Customer") {
          this.kingAssembleEntity.kingAssembleEntity.productShipperCode =
            row.customerCode;
          this.kingAssembleEntity.kingAssembleEntity.productShipperName =
            row.customerName;
        }
      } else if (this.title == "库存组") {
      } else if (this.title == "物料编码") {
        this.kingAssembleEntity.kingAssembleDetailEntities[
          this.count
        ].materialCode = row.materialCode;
        this.kingAssembleEntity.kingAssembleDetailEntities[
          this.count
        ].materialName = row.materialName;
        this.kingAssembleEntity.kingAssembleDetailEntities[this.count].model =
          row.model;
        this.kingAssembleEntity.kingAssembleDetailEntities[this.count].unit =
          row.unit;
        // this.kingAssembleEntity.kingAssembleDetailEntities[
        //   this.count
        // ].bomVersion = row.bomVersion;
        this.flag = 1;
      } else if (this.title == "单位") {
        this.kingAssembleEntity.kingAssembleDetailEntities[this.count].unit =
          row.meteringUnitName;
        this.kingAssembleEntity.kingAssembleDetailEntities[
          this.count
        ].materialUnit = row.meteringUnitCode;
        this.flag = 2;
      } else if (this.title == "仓库") {
        this.kingAssembleEntity.kingAssembleDetailEntities[
          this.count
        ].warehouseCode = row.wareCode;
        this.kingAssembleEntity.kingAssembleDetailEntities[
          this.count
        ].warehouseName = row.wareName;
        this.flag = 3;
      } else if (this.title == "参照bom版本") {
        this.kingAssembleEntity.kingAssembleDetailEntities[
          this.count
        ].bomVersion = row.bomVersion;
        this.flag = 4;
      } else if (this.title == "子项物料编码") {
        this.kingAssembleDetailEntitiesChid[this.count].materialCode =
          row.materialCode;
        this.kingAssembleDetailEntitiesChid[this.count].materialName =
          row.materialName;
        this.kingAssembleDetailEntitiesChid[this.count].model = row.model;
        this.kingAssembleDetailEntitiesChid[this.count].unit = row.unit;
        this.kingAssembleDetailEntitiesChid[this.count].type = 2;

        this.flag = 1;
      } else if (this.title == "子项单位") {
        this.kingAssembleDetailEntitiesChid[this.count].unit =
          row.meteringUnitName;
        this.kingAssembleDetailEntitiesChid[this.count].materialUnit =
          row.meteringUnitCode;
        this.flag = 2;
        this.kingAssembleDetailEntitiesChid[this.count].type = 2;
      } else if (this.title == "子项仓库") {
        this.kingAssembleDetailEntitiesChid[this.count].warehouseCode =
          row.wareCode;
        this.kingAssembleDetailEntitiesChid[this.count].warehouseName =
          row.wareName;
        this.flag = 3;
        this.kingAssembleDetailEntitiesChid[this.count].type = 2;
      }
    },
    getKingDocType() {
      getKingDocTypeList({}).then((res) => {
        console.log(res);
      });
    },
    selectProject() {
      getMaterial({
        pageNo: 1,
        pageSize: 5,
        materialProperty: 2,
        allowProduce: 1,
      }).then((res) => {
        if (res.code == 200) {
          this.dataList = res.data.records;
        }
      });
    },
    handleDataAdd() {
      if (this.kingAssembleEntity.kingAssembleDetailEntities == undefined) {
        this.kingAssembleEntity.kingAssembleDetailEntities = [];
      }
      let outher = {
        assembleId: "",
        batchNo: "",
        bomVersion: "",
        createBy: "",
        createDate: "",
        createTime: "",
        createUser: "",
        fee: "",
        id: "",
        inventoryStateCode: "",

        materialCode: "",
        materialUnit: "",
        num: "",
        pageNo: 0,
        pageSize: 0,
        params: {},
        remark: "",
        remarks: "",
        searchValue: "",
        type: 0,
        updateBy: "",
        updateDate: "",
        updateTime: "",
        updateUser: "",
        warehouseCode: "",
        warehousePosition: "",
      };
      this.kingAssembleEntity.kingAssembleDetailEntities.push(outher);
      console.log(this.kingAssembleEntity.kingAssembleDetailEntities);
    },
    handleDataAddChid() {
      if (this.kingAssembleDetailEntitiesChid == undefined) {
        this.kingAssembleDetailEntitiesChid = [];
      }
      let outher = {
        assembleId: "",
        batchNo: "",
        bomVersion: "",
        createBy: "",
        createDate: "",
        createTime: "",
        createUser: "",
        fee: "",
        id: "",
        inventoryStateCode: "",

        materialCode: "",
        materialUnit: "",
        num: "",
        pageNo: 0,
        pageSize: 0,
        params: {},
        remark: "",
        remarks: "",
        searchValue: "",
        type: 0,
        updateBy: "",
        updateDate: "",
        updateTime: "",
        updateUser: "",
        warehouseCode: "",
        warehousePosition: "",
      };
      this.kingAssembleDetailEntitiesChid.push(outher);
    },
    handleDataDelete(index, row) {
      this.$confirm("请确认是否要删除此行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.kingAssembleEntity.kingAssembleDetailEntities.splice(index, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleDataDeleteChid(index, row) {
      this.$confirm("请确认是否要删除此行？", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
          this.kingAssembleDetailEntitiesChid.splice(index, 1);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    addNewRow() {
      this.handleDataAdd();
    },
    addNewRowChid() {
      this.handleDataAddChid();
    },

    onSubmit() {
      this.kingAssembleEntity.kingAssembleDetailEntities.push(
        ...this.kingAssembleDetailEntitiesChid
      );
      this.kingAssembleEntity.kingAssembleDetailEntities.id = new Date();
      editKingAssembleList(this.kingAssembleEntity).then((res) => {
        if (res.code === 200) {
          this.$message({
            message: "新增成功！",
            type: "success",
          });
        }
      });
    },
  },
  created() {
    this.selectProject();
    // console.log(this.listid);
    updataKingAssembleList(this.listid).then((res) => {
      if (res.code == 200) {
        this.kingAssembleEntity.kingAssembleEntity =
          res.data.kingAssembleEntity;
        for (let i = 0; i < res.data.kingAssembleDetailEntities.length; i++) {
          if (res.data.kingAssembleDetailEntities[i].type == 1) {
            this.kingAssembleEntity.kingAssembleDetailEntities.push(
              res.data.kingAssembleDetailEntities[i]
            );
          } else if (res.data.kingAssembleDetailEntities[i].type == 2) {
            this.kingAssembleDetailEntitiesChid.push(
              res.data.kingAssembleDetailEntities[i]
            );
          }
        }
      }
    });
  },
};
</script>
<style lang="scss" scoped>
.divider {
  margin: 0;
}
.el-icon-search {
  margin-top: 70% !important;
}
.openBOM {
  margin-left: 30px;
}
</style>
